/**
 * 文件名称:  AbstractInterceptor.java
 * 文件版权:  SunShade Technologies Co., Ltd. Copyright 2000-2020,  All rights reserved
 * 文件描述:  <描述>
 * 修改作者:  LiXiangDong
 * 修改时间:  Jan 10, 2013
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.sunshade.common.struts;

import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.sunshade.service.login.action.LoginAction;

/**
 * 
 * @author  LiXiangDong
 * @version V1.0, Jan 10, 2013
 */
public class AbstractInterceptor implements Interceptor
{
    
    /** 注释内容 */
    private static final long serialVersionUID = -1456984018674576953L;
    
    public static final String LOGIN_KEY = "LOGIN";
    
    public static final String LOGIN_PAGE = "error";
    
    private static final String LOGIN = "login";
    
    public void destroy()
    {
        
    }
    
    public void init()
    {
        
    }
    
    public String intercept(ActionInvocation actionInvocation) throws Exception
    {
        // 对LoginAction不做该项拦截
        Object action = actionInvocation.getAction();
        if (action instanceof LoginAction)
        {
            return actionInvocation.invoke();
        }
        // 确认Session中是否存在LOGIN
        Map<String, Object> session = actionInvocation.getInvocationContext()
                .getSession();
        String login = (String)session.get(LOGIN_KEY);
        if (login != null && login.length() > 0)
        {
            // 存在的情况下进行后续操作。
            return actionInvocation.invoke();
        }
        else
        {
            // 否则终止后续操作，返回LOGIN
            return LOGIN;
            
        }
    }
    
}
